// pages/businessList/businessList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    businessList:[],
    flag: true,
    page: 1,
    pageSize: 5,
    total: 0,
  },

  getBusinessList() {
      wx.showLoading({
        title: '数据加载中...'
      })
    wx.request({
      url: 'http://localhost:8080/dataList',
      method: 'GET',
      data: {
        _page : this.data.page,
        _limit: this.data.pageSize
      },
      success: (res) => {
        console.log(res)
        this.setData({
          businessList: [...this.data.businessList, ...res.data],
          total: res.header['count'] - 0
        })
      }
    })
   
    wx.hideLoading()
    wx.stopPullDownRefresh()
  },

  details(e){
    // console.log(e)
    // for(let i = 0; i < this.data.total; i++){
    //   if(e.currentTarget.dataset.info == i){}
    // }
    if(e.currentTarget.dataset.info == 0){
      wx.navigateTo({
        url: '../serveDetails/serveDetails'
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBusinessList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      page: 1,
      businessList: [],
      total: 0,
      flag: true
    })
    this.getBusinessList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.page * this.data.pageSize >= this.data.total){
        this.setData({
          flag: false,
      })
    }else{
      this.setData({
        page: this.data.page + 1,
        total: this.data.businessList.length
      })
      this.getBusinessList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})